package com.ve.downloader;


import java.util.Arrays;

public abstract class BufferSerial implements SerialInterface {

    private byte[] buffer = new byte[1024];

    private String name;
    private boolean bluetooth;

    @Override
    public byte[] read(int size) {
        if (size > buffer.length) {
            buffer = new byte[size];
        }

        int i = read(buffer, size);
        if (i <= 0) {
            return new byte[0];
        }
        return Arrays.copyOfRange(buffer, 0, i);
    }


    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setBluetooth(boolean bluetooth) {
        this.bluetooth = bluetooth;
    }

    public boolean isBluetooth() {
        return bluetooth;
    }

    public abstract void close();
}
